package net.sparrow.module;

import org.lwjgl.input.Keyboard;

import net.minecraft.src.KeyBinding;
import net.sparrow.Sparrow;
import net.sparrow.cmd.CommandHandler;
import net.sparrow.event.DataField;
import net.sparrow.event.SpEventListener;
import net.sparrow.event.SpTickEvent;
import net.sparrow.util.Util;

public class SneakModule extends Module {

	@DataField( id="player.sneaktoggle")
	public Boolean sneak = false;
	
	public boolean isSettable = true;
	public boolean sneakState = false;
	
	@SpEventListener
	public void onFrame(SpTickEvent e) {
		if(!sneak) {
			return; //sneak is off
		}
		KeyBinding sneakBind = Sparrow.mc().minecraft().gameSettings.keyBindSneak;
		boolean keybindPressed = Keyboard.isKeyDown(sneakBind.keyCode);
		if (!keybindPressed) {
			isSettable = true;
		}
		if(Sparrow.mc().player().isSprinting()) {
			sneakState = false;
			sneakBind.pressed = false;
		}
		if(isSettable && sneak && keybindPressed) {
			isSettable = false;
			sneakState = !sneakState;
			Sparrow.mc().player().setSprinting(false);
		}
		if(sneak && !Sparrow.mc().player().isInWater()) {
			sneakBind.pressed = sneakState;
		}

	}
	
	public CommandHandler loadCommands() {
		return new CommandHandler().withDefaultToggle("player.sneaktoggle");
	}
	
}
